import 'package:FlutterRoute/common/models/product_model_entity.dart';

productModelEntityFromJson(ProductModelEntity data, Map<String, dynamic> json) {
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['name'] != null) {
		data.name = json['name'].toString();
	}
	if (json['link'] != null) {
		data.link = json['link'].toString();
	}
	if (json['poster'] != null) {
		data.poster = json['poster'].toString();
	}
	if (json['description'] != null) {
		data.description = json['description'].toString();
	}
	if (json['originPrice'] != null) {
		data.originPrice = json['originPrice'] is String
				? double.tryParse(json['originPrice'])
				: json['originPrice'].toDouble();
	}
	if (json['onSalePrice'] != null) {
		data.onSalePrice = json['onSalePrice'] is String
				? double.tryParse(json['onSalePrice'])
				: json['onSalePrice'].toDouble();
	}
	if (json['isExpired'] != null) {
		data.isExpired = json['isExpired'];
	}
	if (json['onSaleStart'] != null) {
		data.onSaleStart = json['onSaleStart'].toString();
	}
	if (json['onSaleEnd'] != null) {
		data.onSaleEnd = json['onSaleEnd'].toString();
	}
	return data;
}

Map<String, dynamic> productModelEntityToJson(ProductModelEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['id'] = entity.id;
	data['name'] = entity.name;
	data['link'] = entity.link;
	data['poster'] = entity.poster;
	data['description'] = entity.description;
	data['originPrice'] = entity.originPrice;
	data['onSalePrice'] = entity.onSalePrice;
	data['isExpired'] = entity.isExpired;
	data['onSaleStart'] = entity.onSaleStart;
	data['onSaleEnd'] = entity.onSaleEnd;
	return data;
}